<script lang="ts" setup>
import Icon from "./eq-icon.vue"

const props = defineProps({
  eq: {
    type: Object,
    default: () => {}
  },
  notUseIsland: {
    type: Boolean,
    default: false
  },
  smallIcon: {
    type: Boolean,
    default: false
  },
  showTips: {
    type: Boolean,
    default: false
  },
  gray: {
    type: Boolean,
    default: false
  }
})
  
const test = () => {
  if (props.showTips && props.eq && props.eq.id) {
    if (props.eq.groupId == 10 && props.eq.props && props.eq.props.length > 0) {
      if (typeof (props.eq.props[0]) == "number") {
        // eslint-disable-next-line vue/no-mutating-props
        props.eq.propids = props.eq.props.join("-")
      } else {
        const prop = []
        for (const item of props.eq.props) {
          prop.push(item.id)
        }

        // eslint-disable-next-line vue/no-mutating-props
        props.eq.propids = prop.join("-")
      }
    }
    if (props.eq.island && props.eq.island.groupId == 10 && props.eq.island.props && props.eq.island.props.length > 0) {
      if (typeof (props.eq.island.props[0]) == "number") {
        // eslint-disable-next-line vue/no-mutating-props
        props.eq.island.propids = props.eq.island.props.join("-")
      } else {
        const prop = []
        for (const item of props.eq.island.props) {
          prop.push(item.id)
        }

        // eslint-disable-next-line vue/no-mutating-props
        props.eq.island.propids = prop.join("-")
      }
    }

    let url = `/pages/equipment/equip/equip?id=${props.eq.id}`
    if (props.eq.island) {
      url = `${url}&island=${props.eq.island.id}`
    }

    if (props.eq.propids) {
      url = `${url}&propids=${props.eq.propids}`
    }

    if (props.eq.island && props.eq.island.propids) {
      url = `${url}&islandpps=${props.eq.island.propids}`
    }

    uni.navigateTo({
      url
    })
  }
}
</script>

<template>
  <view class="eq-tips">
    <Icon :small-icon="smallIcon" :eq="eq" :not-use-island="notUseIsland" :gray="gray" @clickeq="test" />
  </view>
</template>

<style scoped lang="scss">
.eq-tips {
  display: inline;
}
</style>
